package cn.controller;

import cn.entity.Detail;
import cn.entity.Result;
import cn.entity.Transfer;
import cn.entity.WorkOrder;
import cn.service.DetailService;
import cn.service.TransferService;
import cn.service.WorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/work/admin")
public class WorkOrderController {
    @Autowired
    WorkOrderService workOrderService;
    @Autowired
    TransferService transferService;
    @Autowired
    DetailService detailService;

    @RequestMapping("")
    public ModelAndView work(){
        return new ModelAndView("work/company/work");
    }

    @RequestMapping("toPrint")
    public ModelAndView toPrint(){
        return new ModelAndView("print");
    }

    @RequestMapping("/index/{pageNum}/{pageSize}")
    public Result index(@PathVariable("pageNum")int pageNum, @PathVariable("pageSize")int pageSize, @RequestBody HashMap<String,Object> map){
        return new Result(true,"成功",workOrderService.selectPage(pageNum,pageSize,map));
    }

    @RequestMapping("/detail")
    public ModelAndView detail(){
        return new ModelAndView("work/work-detail");
    }


    @RequestMapping("/showDetail/{id}")
    public Map<String, Object> showDetail(@PathVariable("id")Long id){
        Map<String, Object> map = workOrderService.showDetail(id);
        List<Map<String, Object>> transfers = transferService.detailList(id);
        List<Detail> details = detailService.detailList(id);
        map.put("transfers",transfers);
        map.put("details",details);
        return map;
    }
}
